package com.mmx.baseservice.common.utils;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.mmx.baseservice.common.config.KeyConfig;
import com.mmx.baseservice.common.utils.encrypt.MD5Util;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author
 */
public class UUIDUtil {

    private static AtomicLong timeMills = new AtomicLong(0);

    /**
     * 获取唯一时间戳值
     * @return
     */
    public static Long getTimeId(){
        while (true){
            long currentTimeMillis = System.nanoTime();
            long currentMill = timeMills.get();
            if(currentTimeMillis > currentMill && timeMills.compareAndSet(currentMill, currentTimeMillis)){
                //返回唯一时间戳
                return currentTimeMillis;
            }
        }
    }

    /**
     * 获取 唯一码
     * @return
     */
    public static String getCode(){
        Long timeId = getTimeId();
        return MD5Util.MD5Encode(timeId.toString(), "UTF-8");
    }

    public static void main(String[] args) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String encode = bCryptPasswordEncoder.encode("123123"+KeyConfig.KEY_PWD);
        System.out.println(encode);
        System.out.println(bCryptPasswordEncoder.matches("123123"+KeyConfig.KEY_PWD, encode));
    }

}
